﻿namespace Microsoft.SharePoint.Client
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;

    [ScriptType("SP.ListCollection", ServerTypeId="{1e78b736-61f0-441c-a785-10fc25387c8d}")]
    public class ListCollection : ClientObjectCollection<List>
    {
        [EditorBrowsable(EditorBrowsableState.Never)]
        public ListCollection(ClientRuntimeContext Context, ObjectPath ObjectPath) : base(Context, ObjectPath)
        {
        }

        [Remote]
        public List Add(ListCreationInformation parameters)
        {
            if (base.Context.ValidateOnClient)
            {
                if (parameters == null)
                {
                    throw ClientUtility.CreateArgumentNullException("parameters");
                }
                if (parameters != null)
                {
                    if (parameters.Title == null)
                    {
                        throw ClientUtility.CreateArgumentNullException("parameters.Title");
                    }
                    if ((parameters.Title != null) && (parameters.Title.Length > 0xff))
                    {
                        throw ClientUtility.CreateArgumentException("parameters.Title");
                    }
                }
            }
            List list = new List(base.Context, new ObjectPathMethod(base.Context, base.Path, "Add", new object[] { parameters }));
            list.Path.SetPendingReplace();
            ObjectIdentityQuery query = new ObjectIdentityQuery(list.Path);
            base.Context.AddQueryIdAndResultObject(query.Id, list);
            base.Context.AddQuery(query);
            base.AddChild(list);
            list.InitFromCreationInformation(parameters);
            return list;
        }

        [Remote]
        public List EnsureSiteAssetsLibrary()
        {
            List list = new List(base.Context, new ObjectPathMethod(base.Context, base.Path, "EnsureSiteAssetsLibrary", null));
            list.Path.SetPendingReplace();
            ObjectIdentityQuery query = new ObjectIdentityQuery(list.Path);
            base.Context.AddQueryIdAndResultObject(query.Id, list);
            base.Context.AddQuery(query);
            return list;
        }

        [Remote]
        public List EnsureSitePagesLibrary()
        {
            List list = new List(base.Context, new ObjectPathMethod(base.Context, base.Path, "EnsureSitePagesLibrary", null));
            list.Path.SetPendingReplace();
            ObjectIdentityQuery query = new ObjectIdentityQuery(list.Path);
            base.Context.AddQueryIdAndResultObject(query.Id, list);
            base.Context.AddQuery(query);
            return list;
        }

        [Remote]
        public List GetById(Guid uniqueId)
        {
            Dictionary<Guid, List> dictionary;
            object obj2;
            if (base.ObjectData.MethodReturnObjects.TryGetValue("GetById", out obj2))
            {
                dictionary = (Dictionary<Guid, List>) obj2;
            }
            else
            {
                dictionary = new Dictionary<Guid, List>();
                base.ObjectData.MethodReturnObjects["GetById"] = dictionary;
            }
            List list = null;
            if (!dictionary.TryGetValue(uniqueId, out list))
            {
                list = new List(base.Context, new ObjectPathMethod(base.Context, base.Path, "GetById", new object[] { uniqueId }));
                dictionary[uniqueId] = list;
            }
            return list;
        }

        [Remote]
        public List GetByTitle(string strListName)
        {
            Dictionary<string, List> dictionary;
            object obj2;
            if (base.Context.ValidateOnClient)
            {
                if (strListName == null)
                {
                    throw ClientUtility.CreateArgumentNullException("strListName");
                }
                if ((strListName != null) && (strListName.Length == 0))
                {
                    throw ClientUtility.CreateArgumentException("strListName");
                }
                if ((strListName != null) && (strListName.Length > 0xff))
                {
                    throw ClientUtility.CreateArgumentException("strListName");
                }
            }
            if (base.ObjectData.MethodReturnObjects.TryGetValue("GetByTitle", out obj2))
            {
                dictionary = (Dictionary<string, List>) obj2;
            }
            else
            {
                dictionary = new Dictionary<string, List>(StringComparer.OrdinalIgnoreCase);
                base.ObjectData.MethodReturnObjects["GetByTitle"] = dictionary;
            }
            List list = null;
            if (!dictionary.TryGetValue(strListName, out list))
            {
                list = new List(base.Context, new ObjectPathMethod(base.Context, base.Path, "GetByTitle", new object[] { strListName }));
                dictionary[strListName] = list;
                ObjectIdentityQuery query = new ObjectIdentityQuery(list.Path);
                base.Context.AddQueryIdAndResultObject(query.Id, list);
                base.Context.AddQuery(query);
            }
            return list;
        }

        protected override bool InitOnePropertyFromJson(string peekedName, JsonReader reader)
        {
            bool flag = base.InitOnePropertyFromJson(peekedName, reader);
            if (flag)
            {
                return flag;
            }
            return flag;
        }
    }
}

